package com.wanlian.dao.impl;

import com.wanlian.common.PageCondition;
import com.wanlian.dao.BlackListDao;
import com.wanlian.dao.CardDao;
import com.wanlian.entity.BlackList;
import com.wanlian.entity.Card;
import com.wanlian.model.ResultModel;
import com.wanlian.util.DateUtil;
import com.wanlian.vo.Page;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class BlackListDaoImpl extends GenericDaoImpl<BlackList> implements BlackListDao {

    public BlackListDaoImpl() {
        super(BlackList.class);
    }



    @Override
    public ResultModel queryBlackList(PageCondition pageCondition,int deviceId) {
        ResultModel resultModel = new ResultModel();
        resultModel.setBresult(true);
        StringBuffer sqlWhere = new StringBuffer(" where 1 = 1");
        ArrayList<Object> params = new ArrayList<Object>();

            sqlWhere.append(" and deviceid=?");
            params.add(deviceId+"");

        List<BlackList> lists = new ArrayList<BlackList>();
        String hql = String.format(" from %s  ", entityClassName(),sqlWhere.toString());
        lists = this.queryForListByPage(hql+sqlWhere, params.toArray(), pageCondition.getPage());
        resultModel.setObject(lists);
        String countHql = String.format("select count(*) from  %s "+ sqlWhere, entityClassName(),params.toString());
        Long count = this.queryCount(countHql, params.toArray());
        resultModel.setCount(count);
        return resultModel;
    }

    public  BlackList queryByMacId(String deviceId,String id){
        String hql = String.format("from %s where deviceid=? and  macid=?", entityClassName());
        BlackList blackList = this.queryForObject(hql, new Object[]{deviceId,id});
        return blackList;
    }


    @Override
    public long queryCountById(int deviceId) {
        String countsql = String.format("select count(*) from %s where   deviceid=? ", entityClassName());
        long count = this.queryCount(countsql, new Object[]{deviceId});
        return count;
    }

}
